import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2021-05-05
 * Time: 12:45
 */
public class TestMain11 {

    public static void main(String[] args) {
        randomWord();
    }

    public static void calculate() {
        int firstSum = 0;
        int secondSum = 0;
        for (int i = 1; i <= 100; i++) {
            firstSum += i;
            int tmp = (i % 3) * (i % 5);
            switch (tmp) {
                case 0:
                    secondSum += i;
                    break;
                default:
                    break;
            }
        }

        System.out.println(firstSum);
        System.out.println(secondSum);
    }

    public static void randomWord() {
        String word = randomWord(20);
        char[] chars = word.toCharArray();
        largestLexicographicWord(chars, 0);
        word = "";
        for (int i = 0; i < 20; i++) {
            word += chars[i];
        }
        System.out.println(word);
    }

    public static void largestLexicographicWord(char[] chars, int index) {
        if (index >= chars.length) {
            return;
        }
        char minChar = chars[index];
        int minIndex = index;
        for (int i = index + 1; i < chars.length; i++) {
            if (compare(minChar, chars[i]) > 0) {
                minChar = chars[i];
                minIndex = i;
            }
        }
        if (minIndex != index) {
            chars[minIndex] = chars[index];
            chars[index] = minChar;
        }
        largestLexicographicWord(chars, index + 1);
    }

    private static int compare(char ch1, char ch2) {
        if (ch1 >= 'a' && ch1 <= 'z') {
            if (ch2 >= 'a' && ch2 <= 'z') {
                return Character.compare(ch1, ch2);
            }
            return 1;
        } else {
            if (ch2 >= 'a' && ch2 <= 'z') {
                return -1;
            }
            return Character.compare(ch1, ch2);
        }
    }

    public static String randomWord(int length) {
        Random random = new Random();
        String word = "";
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(26);
            if (random.nextBoolean()) {
                word += (char) ('A' + index);
            } else {
                word += (char) ('a' + index);
            }
        }
        return word;
    }
}
